<template>
    <div class="login-container">
        <!-- 背景图片 -->
        <div class="background-image"></div>
        
        <!-- 半透明黑色覆盖层 -->
        <div class="overlay">
            <!-- 登录表单容器 -->
            <div class="login-form-container">
                <div class="login-header">
                    <h1 class="system-title">仓储管理系统</h1>
                    <h2 class="system-subtitle">Warehouse Management System</h2>
                </div>
                
                <el-form ref="ruleFormRef" :model="ruleForm" status-icon :rules="rules"
                    label-width="auto" class="login-form">
                    <div class="input-group">
                        <div class="input-field">
                            <div class="input-icon">
                                <el-icon><User /></el-icon>
                                
                            </div>
                            <el-input 
                                v-model="ruleForm.UserName" 
                                type="text" 
                                autocomplete="off"
                                placeholder="请输入用户名"
                                class="custom-input"
                            />
                        </div>
                        
                        <div class="input-field">
                            <div class="input-icon">
                                <el-icon><Lock /></el-icon>
                            </div>
                            <el-input 
                                v-model="ruleForm.UserPass" 
                                show-password 
                                autocomplete="off"
                                placeholder="请输入登录密码"
                                class="custom-input"
                            />
                        </div>
                    </div>
                    
                    <div class="button-group">
                        <el-button 
                            type="primary" 
                            @click="submitForm(ruleFormRef)"
                            class="login-button"
                        >
                            登录
                        </el-button>
                        
                        <el-button 
                            @click="resetForm(ruleFormRef)"
                            class="reset-button"
                        >
                            重置
                        </el-button>
                    </div>
                </el-form>
            </div>
        </div>
        
        <!-- 版权信息 -->
        <div class="copyright">
            Copyright© Axure Pro, All Rights Reserved
        </div>
    </div>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
import { User, Lock } from '@element-plus/icons-vue'

import { readB } from '@/http/axiosHelper'
import { dataType } from 'element-plus/es/components/table-v2/src/common.mjs'
import { useRouter } from 'vue-router'
const user = useRouter();
const ruleFormRef = ref<FormInstance>()



const validatePass = (rule: any, value: any, callback: any) => {
    if (value === '') {
        callback(new Error('用户名不能为空'))
    } else {
        if (ruleForm.UserName !== '') {
            if (!ruleFormRef.value) return
            ruleFormRef.value.validateField('checkPass')
        }
        callback()
    }
}
const validatePass2 = (rule: any, value: any, callback: any) => {
    if (value === '') {
        callback(new Error('密码不能为空'))
    } else if (value !== ruleForm.UserPass) {
        callback(new Error("Two inputs don't match!"))
    } else {
        callback()
    }
}

const ruleForm = reactive({
    UserName: '',
    UserPass: ''
})

const rules = reactive<FormRules<typeof ruleForm>>({
    UserName: [{ validator: validatePass, trigger: 'blur' }],
    UserPass: [{ validator: validatePass2, trigger: 'blur' }],
})

const submitForm = (formEl: FormInstance | undefined) => {
    if (!formEl) return
    formEl.validate((valid) => {
        if (valid) {
            readB.get("/api/Management/Loing", {
                params: {
                    UserName: ruleForm.UserName,
                    UserPass: ruleForm.UserPass
                }
            })
                .then(res => {
                    if (res.data.code == 200) {
                        ElMessage.success(res.data.msg);
                        localStorage.setItem("id", res.data.data.id)
                        localStorage.setItem("userName", res.data.data.userName)
                        localStorage.setItem("roleId", res.data.data.roleId)
                        localStorage.setItem("deptId", res.data.data.deptId)
                        localStorage.setItem("Token", res.data.jwt)

                       
                        user.push("/Main");
                    }
                    else {
                        ElMessage.error(res.data.msg);
                    }
                })
        } else {
            console.log('error submit!')
        }
    })
}

const resetForm = (formEl: FormInstance | undefined) => {
    if (!formEl) return
    formEl.resetFields()
}
</script>

<style scoped>
/* 确保页面没有默认边距和填充 */
:deep(body), :deep(html) {
    margin: 0 !important;
    padding: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
}

/* 确保根元素也没有滚动条 */
:deep(#app) {
    margin: 0 !important;
    padding: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
}

/* 确保所有元素都不会产生滚动 */
:deep(*) {
    box-sizing: border-box;
}
.login-container {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
    min-width: 100vw !important;
    min-height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
}

.background-image {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background-image: url('https://bpic.588ku.com/back_origin_min_pic/23/05/06/9ba23fdbfeeca16698f3a56858c58e53.jpg');
    background-size: cover !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    background-attachment: fixed !important;
    z-index: 1;
    filter: brightness(1.0) contrast(1.1);
    min-width: 100vw !important;
    min-height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
}

.overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background-color: rgba(0, 0, 0, 0.3);
    z-index: 2;
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 100vw !important;
    min-height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
}

.login-form-container {
    width: 90%;
    max-width: 2000px;
    background-color: rgba(51, 51, 51, 0.8);
    border-radius: 0px;
    padding: 60px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
}

.login-header {
    text-align: center;
    margin-bottom: 40px;
}

.system-title {
    color: white;
    font-size: 48px;
    font-weight: bold;
    margin: 0 0 15px 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.system-subtitle {
    color: #cccccc;
    font-size: 24px;
    font-weight: normal;
    margin: 0;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.login-form {
    width: 100%;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 30px;
}

.button-group {
    display: flex;
    align-items: center;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.input-field {
    position: relative;
    flex: 1;
    max-width: 300px;
}

.input-icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #ccc;
    z-index: 3;
    font-size: 16px;
}

.input-icon .el-icon {
    font-size: 16px;
    color: #ccc;
}

.custom-input {
    width: 100%;
}

.custom-input :deep(.el-input__wrapper) {
    background-color: white;
    border-radius: 0px;
    padding-left: 40px;
    height: 50px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 1px solid #dcdfe6;
}

.custom-input :deep(.el-input__inner) {
    height: 50px;
    font-size: 16px;
    color: #333;
}

.custom-input :deep(.el-input__inner::placeholder) {
    color: #999;
}

.login-button {
    padding: 15px 30px;
    border-radius: 0px;
    background-color: white;
    border: 2px solid #333;
    color: #333;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    margin-right: 0px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.login-button:hover {
    background-color: #333;
    color: white;
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.reset-button {
    padding: 15px 30px;
    border-radius: 0px;
    background-color: white;
    border: 2px solid #dcdfe6;
    color: #606266;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.reset-button:hover {
    background-color: #f5f7fa;
    border-color: #409eff;
    color: #409eff;
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.copyright {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: #cccccc;
    font-size: 12px;
    z-index: 3;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

/* 响应式设计 */
@media (max-width: 768px) {
    .login-form-container {
        width: 90%;
        padding: 30px 20px;
    }
    
    .input-group {
        flex-direction: column;
        gap: 20px;
    }
    
    .input-field {
        max-width: 100%;
    }
    
    .system-title {
        font-size: 24px;
    }
    
    .system-subtitle {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .login-form-container {
        width: 95%;
        padding: 20px 15px;
    }
    
    .system-title {
        font-size: 20px;
    }
    
    .system-subtitle {
        font-size: 14px;
    }
}
</style>
